package com.coolingme.springboot.dubbo.springbootdubbosampleprovider.service;

import com.coolingme.springboot.dubbo.ISayHelloService;
import org.apache.commons.lang3.RandomUtils;
import org.apache.dubbo.config.annotation.DubboService;

/**
 * dubbo中的@service标签已弃用
 * registry：配置多个配置中心
 * version：配置版本
 *
 * @author wangyue
 * @date 2022/10/5 14:20
 */
@DubboService(registry = {"nanjing", "shanghai"}, version = "2.0")
public class SayHelloService2Impl implements ISayHelloService {


    @Override
    public String sayHello(String name) {
        try {
            int i = RandomUtils.nextInt(300, 800);
            System.out.println(Thread.currentThread().getName() + " 睡眠" + i + "ms");
            Thread.sleep(i);

            if (i > 500) {
                System.out.println(1 / 0);
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        return Thread.currentThread().getName() + "         [Version 2.0] Hello " + name;
    }

}
